/**
 * https://github.com/webpack/webpack/blob/master/test/configCases/plugins/banner-plugin/webpack.config.js
 */

const webpack = require('webpack');
const TerserPlugin = require("terser-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin') // 自动引用资源
const { resolve } = require('path')

module.exports = {
  // 配置 loader
  entry: './src/index.js',
  output: {
    // 文件名
    filename: 'built.js',
    // 输出路径
    // __dirname nodejs的变量，代表当前文件的目录绝对路径
    path: resolve(__dirname, 'build')
  },
  plugins: [
    // 配置plugins的配置
    // html-webpack-plugin
    // 功能：默认会创建一个空的html，自动移入打包输出的所有资源(js/css)
    new HtmlWebpackPlugin({
      // 创建/复制 一个html文件 (使用html模板)
      template: './src/index.html', // 最好使用 绝对路径
    }),

    // new webpack.BannerPlugin({
		// 	banner: ({ chunk }) => {
    //     console.log('chunk=', chunk)
    //     return `multiline\nbanner\n${chunk.name}`
    //   },
    //   entryOnly: false,
    // }),
    
    // new webpack.BannerPlugin("banner is a string"),
    // new webpack.BannerPlugin(() => "banner is a function"),
  ],
  optimization: {
    minimize: true,
    minimizer: [
      // https://webpack.docschina.org/plugins/terser-webpack-plugin/
      new TerserPlugin({
        extractComments: {
          banner: () => {
            return "--srxboys--";
          },
        },
      }),
    ],
  },
}